""" Saber3D package for python programming. Put all your very usefull programms here """

def range_2(sizeX, sizeY):
    for x in range(sizeX):
        for y in range(sizeY):
            yield x, y

def range_table(rows, columns):
    for r in range(rows):
        for c in range(columns):
            yield r, c
            
TabSize = 3

TypeMatching = {
    "string":   "dsSTRING",
    "vec3":     "m3dV",
    "vec4":     "m4dV",
    "map":      "ds::MAP",
    "set":      "ds::MAP",
    "array":    "dsVECTOR"
}

def BuildName(name):
    if name in TypeMatching.keys():
        return TypeMatching[name]
    else:
        return name

def BuildArrayName(subType):
    if subType[len(subType) - 1] == '>':
        return "dsVECTOR<" + subType + " >"
    else:
        return "dsVECTOR<" + subType + ">"

def BuildSetName(subType):
    if subType[len(subType) - 1] == '>':
        return "ds::MAP<" + subType + " >"
    else:
        return "ds::MAP<" + subType + ">"

def BuildSubname(type, name):
    return "%s::%s" % (type, name)

def BuildTemplateArgs(type, args):
    res = type + "<"
    for k in range(len(args) - 1):
        res += args[k] + ", "
    res += args[len(args) - 1]

    if res[len(res) - 1] == '>':
        res += " >"
    else:
        res += ">"
        
    return res

def CalcMinWidth(array, getter = None, align = 3, tabs = 1):
    if isinstance(getter, str):
        name = getter
        getter = lambda x: eval("x." + name) 

    if getter is None:
        res = max([len(p) for p in array])
    else:
        res = max([len(getter(p)) for p in array])

    res = 3 * int((res + align - 1) / 3 + 0.5)
    res += align * tabs
    return res
